{% extends "base.html" %}

{% block title %}编辑图书{% endblock %}

{% block content %}
<h2>编辑图书</h2>
<form method="POST" enctype="multipart/form-data">
    <div class="mb-3">
        <label for="title" class="form-label">书名</label>
        <input type="text" class="form-control" id="title" name="title" value="{{ book.title }}" required>
    </div>
    <div class="mb-3">
        <label for="author" class="form-label">作者</label>
        <input type="text" class="form-control" id="author" name="author" value="{{ book.author }}" required>
    </div>
    <div class="mb-3">
        <label for="description" class="form-label">描述</label>
        <textarea class="form-control" id="description" name="description" rows="3">{{ book.description }}</textarea>
    </div>
    <div class="mb-3">
        <label for="isbn" class="form-label">ISBN</label>
        <input type="text" class="form-control" id="isbn" name="isbn" value="{{ book.isbn }}">
    </div>
    <div class="mb-3">
        <label for="publication_date" class="form-label">出版日期</label>
        <input type="date" class="form-control" id="publication_date" name="publication_date" value="{{ book.publication_date }}">
    </div>
    <div class="mb-3">
        <label for="category" class="form-label">分类</label>
        <input type="text" class="form-control" id="category" name="category" value="{{ book.category }}">
    </div>
    <div class="mb-3">
        <label for="status" class="form-label">状态</label>
        <select class="form-select" id="status" name="status">
            <option value="available" {% if book.status == 'available' %}selected{% endif %}>可用</option>
            <option value="unavailable" {% if book.status == 'unavailable' %}selected{% endif %}>不可用</option>
            <option value="reserved" {% if book.status == 'reserved' %}selected{% endif %}>已预约</option>
        </select>
    </div>
    <div class="mb-3">
        <label for="available_copies" class="form-label">可用副本数</label>
        <input type="number" class="form-control" id="available_copies" name="available_copies" value="{{ book.available_copies }}" min="0">
    </div>
    <div class="mb-3">
        <label for="total_copies" class="form-label">总副本数</label>
        <input type="number" class="form-control" id="total_copies" name="total_copies" value="{{ book.total_copies }}" min="0">
    </div>
    <div class="mb-3">
        <label for="cover_image" class="form-label">封面图片</label>
        <input type="file" class="form-control" id="cover_image" name="cover_image">
        {% if book.cover_image %}
        <p class="mt-2">当前封面图片: <img src="{{ url_for('static', filename='images/' + book.cover_image) }}" alt="Cover Image" class="img-thumbnail" style="max-width: 200px;"></p>
        {% endif %}
    </div>
    <button type="submit" class="btn btn-primary">保存</button>
</form>
{% endblock %}
